package gui.product;

import gui.common.Taggable;
import model.entity.Product;

/**
 * Display data class for products.
 */
public class ProductData extends Taggable<Product> implements Comparable<ProductData>
{

  /**
   * Description attribute.
   */
  private String _description;

  /**
   * Size attribute.
   */
  private String _size;

  /**
   * Count attribute.
   */
  private String _count;

  /**
   * Shelf Life attribute
   */
  private String _shelfLife;

  /**
   * Supply attribute.
   */
  private String _supply;

  /**
   * Barcode attribute.
   */
  private String _barcode;

  /**
   * Constructor.
   * 
   * {@pre None}
   * 
   * {@post getDescription() == ""} {@post getSize() == ""} {@post getCount() == ""} {@post
   * getShelfLife() == ""} {@post getSupply() == ""} {@post getBarcode() == ""}
   */
  public ProductData()
  {
    _description = "";
    _size = "";
    _count = "";
    _shelfLife = "";
    _supply = "";
    _barcode = "";
  }

  /**
   * Returns the value of the Barcode attribute.
   */
  public String getBarcode()
  {
    return _barcode;
  }

  /**
   * Sets the value of the Barcode attribute.
   * 
   * @param barcode
   *          New Barcode value
   * 
   *          {@pre barcode != null}
   * 
   *          {@post getBarcode() == barcode}
   */
  public void setBarcode(String barcode)
  {
    _barcode = barcode;
  }

  /**
   * Returns the value of the Description value.
   */
  public String getDescription()
  {
    return _description;
  }

  /**
   * Sets the value of the Description value.
   * 
   * @param description
   *          New Description value
   * 
   *          {@pre description != null}
   * 
   *          {@post getDescription() == description}
   */
  public void setDescription(String description)
  {
    _description = description;
  }

  /**
   * Returns the value of the Size attribute.
   */
  public String getSize()
  {
    return _size;
  }

  /**
   * Sets the value of the Size attribute.
   * 
   * @param size
   *          New Size value
   * 
   *          {@pre size != null}
   * 
   *          {@post getSize() == size}
   */
  public void setSize(String size)
  {
    _size = size;
  }

  /**
   * Returns the value of the Count attribute.
   */
  public String getCount()
  {
    return _count;
  }

  /**
   * Sets the value of the Count attribute.
   * 
   * @param count
   *          New Count value
   * 
   *          {@pre count != null}
   * 
   *          {@post getCount() == count}
   */
  public void setCount(String count)
  {
    _count = count;
  }

  /**
   * Returns the value of the Shelf Life attribute.
   */
  public String getShelfLife()
  {
    return _shelfLife;
  }

  /**
   * Sets the value of the Shelf Life attribute.
   * 
   * @param shelfLife
   *          New Shelf Life value
   * 
   *          {@pre shelfLife != null}
   * 
   *          {@post getShelfLife() == shelfLife}
   */
  public void setShelfLife(String shelfLife)
  {
    _shelfLife = shelfLife;
  }

  /**
   * Returns the value of the Supply attribute.
   */
  public String getSupply()
  {
    return _supply;
  }

  /**
   * Sets the value of the Supply attribute.
   * 
   * @param supply
   *          New Supply value
   * 
   *          {@pre supply != null}
   * 
   *          {@post getSupply() == supply}
   */
  public void setSupply(String supply)
  {
    _supply = supply;
  }

  @Override
  public int hashCode()
  {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((_barcode == null) ? 0 : _barcode.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj)
  {
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (!(obj instanceof ProductData))
      return false;
    ProductData other = (ProductData) obj;
    if (_barcode == null && other._barcode != null)
      return false;
    else if (!_barcode.equals(other._barcode))
      return false;
    return true;
  }

  @Override
  public String toString()
  {
    StringBuilder builder = new StringBuilder();
    builder.append("ProductData [barcode=");
    builder.append(_barcode);
    builder.append(", description=\"");
    builder.append(_description);
    builder.append("\", shelfLife=");
    builder.append(_shelfLife);
    builder.append(", size=");
    builder.append(_size);
    builder.append(", count=");
    builder.append(_count);
    builder.append(", supply=");
    builder.append(_supply);
    builder.append("]");
    return builder.toString();
  }

  @Override
  public int compareTo(ProductData other)
  {
    return _description.compareToIgnoreCase(other._description);
  }
}
